<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>需求管理 - 任务管理系统</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    
    <!-- 自定义样式 -->
    <link rel="stylesheet" href="/css/main.css">
    <link rel="stylesheet" href="/css/requirement-form.css">
</head>
<body>
    <!-- 主导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <i class="bi bi-kanban"></i>
                任务管理系统
            </a>
            
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/projects">
                            <i class="bi bi-folder"></i>
                            项目管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="/requirements">
                            <i class="bi bi-list-check"></i>
                            需求管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/developers">
                            <i class="bi bi-people"></i>
                            开发者管理
                        </a>
                    </li>
                </ul>
                
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i>
                            用户
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="#">个人设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="#">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container-fluid">
        <div class="row">
            <!-- 侧边导航 -->
            <nav class="col-md-2 d-md-block bg-light sidebar">
                <div class="position-sticky pt-3">
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="/requirements">
                                <i class="bi bi-list"></i>
                                需求列表
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="/requirements/create">
                                <i class="bi bi-plus-circle"></i>
                                创建需求
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/requirements/templates">
                                <i class="bi bi-file-earmark-text"></i>
                                需求模板
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/requirements/reports">
                                <i class="bi bi-graph-up"></i>
                                需求报告
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- 主内容区域 -->
            <main class="col-md-10 ms-sm-auto px-md-4">
        <div class="content-container">
            <!-- 面包屑导航 -->
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="/">首页</a></li>
                    <li class="breadcrumb-item"><a href="/requirements">需求管理</a></li>
                    <li class="breadcrumb-item active" id="breadcrumbTitle">创建需求</li>
                </ol>
            </nav>

            <!-- 页面头部 -->
            <div class="page-header">
                <div class="header-content">
                    <h1 class="page-title" id="pageTitle">
                        <i class="bi bi-plus-circle"></i>
                        创建需求
                    </h1>
                    <p class="page-description">填写需求基本信息并管理相关参考文档</p>
                </div>
                <div class="header-actions">
                    <!-- 操作按钮已移除 -->
                </div>
            </div>

            <!-- 需求表单 -->
            <div class="row">
                <!-- 主表单区域 -->
                <div class="col-12">
                    <form id="requirementForm" class="requirement-form">
                        <!-- 基本信息 -->
                        <div class="form-section">
                            <div class="section-header">
                                <h3 class="section-title">
                                    <i class="bi bi-info-circle"></i>
                                    基本信息
                                </h3>
                            </div>
                            
                            <div class="row">
                                <div class="col-12">
                                    <div class="mb-3">
                                        <label for="title" class="form-label required-field">需求标题</label>
                                        <input type="text" class="form-control" id="title" name="title" 
                                               placeholder="请输入需求标题" maxlength="200" required>
                                        <div class="form-text">简洁明确地描述需求的核心内容</div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="projectId" class="form-label required-field">所属项目</label>
                                        <select class="form-select" id="projectId" name="projectId" required>
                                            <option value="">请选择项目</option>
                                            <!-- 项目选项将通过JavaScript动态加载 -->
                                        </select>
                                        <div class="form-text text-muted" id="projectIdHelp" style="display: none;">
                                            <i class="bi bi-info-circle"></i> 编辑模式下项目归属不可修改
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="priority" class="form-label required-field">优先级</label>
                                        <select class="form-select" id="priority" name="priority" required>
                                            <option value="">请选择优先级</option>
                                            <option value="LOW">低</option>
                                            <option value="MEDIUM">中</option>
                                            <option value="HIGH">高</option>
                                            <option value="URGENT">紧急</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="ownerId" class="form-label">负责人</label>
                                        <select class="form-select" id="ownerId" name="ownerId">
                                            <option value="">请选择负责人</option>
                                            <!-- 负责人选项将通过JavaScript动态加载 -->
                                        </select>
                                        <div class="form-text text-muted" id="ownerIdHelp" style="display: none;">
                                            <i class="bi bi-info-circle"></i> 编辑模式下负责人变更需要专门的流程
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="expectedCompletionDate" class="form-label">期望完成日期</label>
                                        <input type="date" class="form-control" id="expectedCompletionDate" 
                                               name="expectedCompletionDate">
                                        <div class="form-text text-muted" id="expectedCompletionDateHelp" style="display: none;">
                                            <i class="bi bi-info-circle"></i> 编辑模式下期望完成日期不可修改
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="mb-3">
                                <label for="description" class="form-label required-field">需求描述</label>
                                <textarea class="form-control" id="description" name="description" 
                                          rows="6" placeholder="请详细描述需求的背景、目标和具体要求" required></textarea>
                                <div class="form-text">详细描述需求的背景、目标、功能要求和验收标准</div>
                            </div>
                            
                            <!-- 编辑模式下的快速保存按钮 -->
                            <div class="edit-mode-actions" id="editModeActions" style="display: none;">
                                <div class="d-flex justify-content-end mt-3 pt-3 border-top">
                                    <button type="submit" class="btn btn-primary" id="quickSaveBtn">
                                        <i class="bi bi-check-circle"></i>
                                        <span>保存修改</span>
                                    </button>
                                </div>
                                <div class="form-text text-muted mt-2 text-end">
                                    <i class="bi bi-info-circle"></i> 仅保存可编辑的字段：标题、描述、优先级
                                </div>
                            </div>
                        </div>

                        <!-- 参考文档管理 -->
                        <div class="form-section">
                            <div class="section-header">
                                <h3 class="section-title">
                                    <i class="bi bi-file-earmark-text"></i>
                                    参考文档
                                </h3>
                                <button type="button" class="btn btn-outline-primary btn-sm" id="addDocumentBtn">
                                    <i class="bi bi-plus"></i>
                                    添加文档
                                </button>
                            </div>
                            
                            <div class="documents-container">
                                <div id="documentsList" class="documents-list">
                                    <!-- 文档列表将通过JavaScript动态生成 -->
                                </div>
                                
                                <div id="noDocuments" class="no-documents">
                                    <div class="text-center text-muted py-4">
                                        <i class="bi bi-file-earmark-plus" style="font-size: 3rem;"></i>
                                        <p class="mt-3 mb-2">暂无参考文档</p>
                                        <p class="small">添加相关的设计文档、原型图或参考资料</p>
                                        <button type="button" class="btn btn-outline-primary" onclick="document.getElementById('addDocumentBtn').click()">
                                            <i class="bi bi-plus"></i>
                                            添加第一个文档
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 表单操作按钮 -->
                        <div class="form-actions">
                            <div class="d-flex justify-content-end">
                                <button type="submit" class="btn btn-primary" id="submitBtn">
                                    <i class="bi bi-check-circle"></i>
                                    <span id="submitText">创建需求</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>


            </div>
        </div>
            </main>
        </div>
    </div>

    <!-- 添加文档模态框 -->
    <div class="modal fade" id="addDocumentModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">
                        <i class="bi bi-file-earmark-plus"></i>
                        添加参考文档
                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="addDocumentForm">
                        <div class="mb-3">
                            <label for="documentTitle" class="form-label">文档标题 *</label>
                            <input type="text" class="form-control" id="documentTitle" required maxlength="200" placeholder="请输入文档标题">
                            <div class="form-text">最多200个字符</div>
                        </div>
                        <div class="mb-3">
                            <label for="documentUrl" class="form-label">文档链接 *</label>
                            <input type="url" class="form-control" id="documentUrl" required maxlength="500" placeholder="https://example.com/document.pdf">
                            <div class="form-text">请输入有效的URL地址，最多500个字符</div>
                        </div>
                        <div class="mb-3">
                            <label for="documentDescription" class="form-label">文档描述</label>
                            <textarea class="form-control" id="documentDescription" rows="3" maxlength="1000" placeholder="简要描述文档内容（可选）"></textarea>
                            <div class="form-text">最多1000个字符</div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="saveDocumentBtn">
                        <i class="bi bi-check"></i> 保存
                    </button>
                </div>
            </div>
        </div>
    </div>



    <!-- Toast 通知 -->
    <div class="toast-container position-fixed top-0 end-0 p-3">
        <!-- 成功提示 -->
        <div id="successToast" class="toast align-items-center text-white bg-success border-0" role="alert">
            <div class="d-flex">
                <div class="toast-body">
                    <i class="bi bi-check-circle me-2"></i>
                    <span id="successMessage">操作成功</span>
                </div>
                <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
            </div>
        </div>
        
        <!-- 错误提示 -->
        <div id="errorToast" class="toast align-items-center text-white bg-danger border-0" role="alert">
            <div class="d-flex">
                <div class="toast-body">
                    <i class="bi bi-exclamation-triangle me-2"></i>
                    <span id="errorMessage">操作失败</span>
                </div>
                <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
            </div>
        </div>
        
        <!-- 信息提示 -->
        <div id="infoToast" class="toast align-items-center text-white bg-info border-0" role="alert">
            <div class="d-flex">
                <div class="toast-body">
                    <i class="bi bi-info-circle me-2"></i>
                    <span id="infoMessage">信息提示</span>
                </div>
                <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
            </div>
        </div>
    </div>

    <!-- 加载遮罩 -->
    <div id="loadingOverlay" class="loading-overlay d-none">
        <div class="loading-content">
            <div class="spinner-border text-primary" role="status">
                <span class="visually-hidden">加载中...</span>
            </div>
            <p class="mt-3 mb-0">处理中，请稍候...</p>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- 自定义JavaScript -->
    <script src="/js/requirement-form.js"></script>
</body>
</html>